package kr.pe.johnkim.app.mobile.rest.controller;

import org.springframework.stereotype.Controller;

import javax.ws.rs.Path;

/**
 * @author : johnkim <cale9797@gmail.com / Bettersoft Inc,.>
 * @Date : 12. 2. 5
 */
@Controller
@Path("/myHistoryGroupController")
public class MyHistoryGroupController {
//    // SLF4J Logging
//	private Logger logger = LoggerFactory.getLogger(MyHistoryGroupController.class);
//
//    @Autowired
//    private MyHistoryGroupService myHistoryGroupService = null;
//
//    @Autowired
//    private MyHistoryCategoryService myHistoryCategoryService = null;
//
//    @Autowired
//    private MyHistoryItemService myHistoryItemService = null;
//
//    @Autowired
//    private MyHistoryCommon myHistoryCommon = null;
//
//    /**
//     * Group 등록 시 Name 중복 확인을 한다.
//     *
//     * @param is
//     * @return
//     * @throws IOException
//     * @throws JSONException
//     */
//    @POST
//    @Path("/checkDuplication")
//    @Consumes({"application/json", "application/xml"})
//    @Produces({"application/json", "application/xml"})
//    public MyHistoryGroup checkDuplication(InputStream is) throws IOException, JSONException {
//        logger.info("checkDuplication");
//
//        BufferedReader br = new BufferedReader(new InputStreamReader(is));
//        String line = br.readLine();
//
//        logger.info("line : {}", line);
//
//        JSONObject jsonGroup = new JSONObject(line);
//        JSONObject jsonGroup2 = jsonGroup.getJSONObject("myHistoryGroup");
//
//        MyHistoryGroup parameterGroup = new MyHistoryGroup();
//
//        parameterGroup.setName(jsonGroup2.getString("name"));
//        parameterGroup.setActivateYn(jsonGroup2.getString("activateYn"));
//        parameterGroup.setMyHistoryMembersId(jsonGroup2.getString("myHistoryMembersId"));
//
//        logger.info("name               : {}", parameterGroup.getName());
//        logger.info("activateYn         : {}", parameterGroup.getActivateYn());
//        logger.info("myHistoryMembersId : {}", parameterGroup.getMyHistoryMembersId());
//
//        return myHistoryGroupService.checkDuplication(parameterGroup);
//    }
//
//    /**
//     * 그룹을 등록 한다.
//     *
//     * @param is
//     * @return MyHistoryGroup
//     * @throws IOException
//     * @throws JSONException
//     */
//    @POST
//    @Path("/registerGroup")
//    @Consumes({"application/json", "application/xml"})
//    @Produces({"application/json", "application/xml"})
//    public MyHistoryGroup registerGroup(InputStream is) throws IOException, JSONException {
//        logger.info("registerGroup");
//
//        BufferedReader br = new BufferedReader(new InputStreamReader(is));
//        String line = br.readLine();
//
//        logger.info("line : {}", line);
//
//        JSONObject jsonGroup = new JSONObject(line);
//        JSONObject jsonGroup2 = jsonGroup.getJSONObject("myHistoryGroup");
//
//        MyHistoryGroup parameterGroup = new MyHistoryGroup();
//
//        parameterGroup.setName(jsonGroup2.getString("name"));
//        parameterGroup.setComment(jsonGroup2.getString("comment"));
//        parameterGroup.setIconUrl(jsonGroup2.getString("iconUrl"));
//        parameterGroup.setOpenGroupYn(jsonGroup2.getString("openGroupYn"));
//        parameterGroup.setFavoriteYn(jsonGroup2.getString("favoriteYn"));
//        parameterGroup.setActivateYn(jsonGroup2.getString("activateYn"));
//        parameterGroup.setModifyDate(jsonGroup2.getString("modifyDate"));
//        parameterGroup.setRegisterDate(jsonGroup2.getString("registerDate"));
//        parameterGroup.setMyHistoryMembersId(jsonGroup2.getString("myHistoryMembersId"));
//
//        logger.info("name               : {}", parameterGroup.getName());
//        logger.info("comment            : {}", parameterGroup.getComment());
//        logger.info("iconUrl            : {}", parameterGroup.getIconUrl());
//        logger.info("openGroupYn        : {}", parameterGroup.getOpenGroupYn());
//        logger.info("favoriteYn         : {}", parameterGroup.getFavoriteYn());
//        logger.info("activateYn         : {}", parameterGroup.getActivateYn());
//        logger.info("modifyDate         : {}", parameterGroup.getModifyDate());
//        logger.info("registerDate       : {}", parameterGroup.getRegisterDate());
//        logger.info("myHistoryMembersId : {}", parameterGroup.getMyHistoryMembersId());
//
//        MyHistoryGroup resultGroup = new MyHistoryGroup();
//
//        if(myHistoryGroupService.registerGroup(parameterGroup)) {
//            resultGroup.setResult("SUCCESS");
//        } else {
//            resultGroup.setResult("FAIL");
//        }
//
//        return resultGroup;
//    }
//
//    /**
//     * Group 목록을 가져 온다.
//     *
//     * @param is
//     * @return
//     * @throws IOException
//     * @throws JSONException
//     */
//    @POST
//    @Path("/selectGroupList")
//    @Consumes({"application/json", "application/xml"})
//    @Produces({"application/json", "application/xml"})
//    public List<MyHistoryGroup> selectGroupList(InputStream is) throws IOException, JSONException {
//        logger.info("selectGroupList");
//
//        BufferedReader br = new BufferedReader(new InputStreamReader(is));
//        String line = br.readLine();
//
//        logger.info("line : {}", line);
//
//        JSONObject jsonGroup = new JSONObject(line);
//        JSONObject jsonGroup2 = jsonGroup.getJSONObject("myHistoryGroup");
//
//        MyHistoryGroup parameterGroup = new MyHistoryGroup();
//
//        parameterGroup.setMyHistoryMembersId(jsonGroup2.getString("myHistoryMembersId"));
//        parameterGroup.setActivateYn(jsonGroup2.getString("activateYn"));
////        parameterGroup.setGroupStart(Integer.parseInt(jsonGroup2.getString("groupStart")));
////        parameterGroup.setGroupCount(Integer.parseInt(jsonGroup2.getString("groupCount")));
//
//        logger.info("activateYn         : {}", parameterGroup.getActivateYn());
//        logger.info("myHistoryMembersId : {}", parameterGroup.getMyHistoryMembersId());
//
////        logger.info("groupStart : {}", parameterGroup.getGroupStart());
////        logger.info("groupCount : {}", parameterGroup.getGroupCount());
//
//        return myHistoryGroupService.selectGroupList(parameterGroup);
//    }
//
//    /**
//     * 그룹을 수정 한다.
//     *
//     * @param is
//     * @return
//     * @throws IOException
//     * @throws JSONException
//     */
//    @POST
//    @Path("/updateGroup")
//    @Consumes({"application/json", "application/xml"})
//    @Produces({"application/json", "application/xml"})
//    public MyHistoryGroup updateGroup(InputStream is) throws IOException, JSONException {
//        logger.info("updateGroup");
//
//        BufferedReader br = new BufferedReader(new InputStreamReader(is));
//        String line = br.readLine();
//
//        logger.info("line : {}", line);
//
//        JSONObject jsonGroup = new JSONObject(line);
//        JSONObject jsonGroup2 = jsonGroup.getJSONObject("myHistoryGroup");
//
//        MyHistoryGroup parameterGroup = new MyHistoryGroup();
//
//        parameterGroup.setIdMyHistoryGroups(jsonGroup2.getString("idMyHistoryGroups"));
//        parameterGroup.setName(jsonGroup2.getString("name"));
//        parameterGroup.setComment(jsonGroup2.getString("comment"));
//        parameterGroup.setIconUrl(jsonGroup2.getString("iconUrl"));
//        parameterGroup.setOpenGroupYn(jsonGroup2.getString("openGroupYn"));
//        parameterGroup.setFavoriteYn(jsonGroup2.getString("favoriteYn"));
//        parameterGroup.setActivateYn(jsonGroup2.getString("activateYn"));
//        parameterGroup.setModifyDate(jsonGroup2.getString("modifyDate"));
//        parameterGroup.setMyHistoryMembersId(jsonGroup2.getString("myHistoryMembersId"));
//
//        logger.info("idMyHistoryGroups  : {}", parameterGroup.getIdMyHistoryGroups());
//        logger.info("name               : {}", parameterGroup.getName());
//        logger.info("comment            : {}", parameterGroup.getComment());
//        logger.info("iconUrl            : {}", parameterGroup.getIconUrl());
//        logger.info("openGroupYn        : {}", parameterGroup.getOpenGroupYn());
//        logger.info("favoriteYn         : {}", parameterGroup.getFavoriteYn());
//        logger.info("activateYn         : {}", parameterGroup.getActivateYn());
//        logger.info("modifyDate         : {}", parameterGroup.getModifyDate());
//        logger.info("myHistoryMembersId : {}", parameterGroup.getMyHistoryMembersId());
//
//        MyHistoryGroup resultGroup = new MyHistoryGroup();
//
//        if(myHistoryGroupService.updateGroup(parameterGroup)) {
//            resultGroup.setResult("SUCCESS");
//        } else {
//            resultGroup.setResult("FAIL");
//        }
//
//        return resultGroup;
//    }
//
//    /**
//     * 그룹을 비활성화 한다.
//     *
//     * @param is
//     * @return MyHistoryGroup
//     * @throws IOException
//     * @throws JSONException
//     */
//    @POST
//    @Path("/updateDeactivateGroup")
//    @Consumes({"application/json", "application/xml"})
//    @Produces({"application/json", "application/xml"})
//    public MyHistoryGroup updateDeactivateGroup(InputStream is) throws IOException, JSONException {
//        logger.info("updateDeactivateGroup");
//
//        BufferedReader br = new BufferedReader(new InputStreamReader(is));
//        String line = br.readLine();
//
//        logger.info("line : {}", line);
//
//        JSONObject jsonGroup = new JSONObject(line);
//        JSONObject jsonGroup2 = jsonGroup.getJSONObject("myHistoryGroup");
//
//        MyHistoryGroup parameterGroup = new MyHistoryGroup();
//
//        parameterGroup.setIdMyHistoryGroups(jsonGroup2.getString("idMyHistoryGroups"));
//        parameterGroup.setActivateYn(jsonGroup2.getString("activateYn"));
//        parameterGroup.setModifyDate(jsonGroup2.getString("modifyDate"));
//        parameterGroup.setMyHistoryMembersId(jsonGroup2.getString("myHistoryMembersId"));
//
//        logger.info("idMyHistoryGroups  : {}", parameterGroup.getIdMyHistoryGroups());
//        logger.info("activateYn         : {}", parameterGroup.getActivateYn());
//        logger.info("modifyDate         : {}", parameterGroup.getModifyDate());
//        logger.info("myHistoryMembersId : {}", parameterGroup.getMyHistoryMembersId());
//
//        MyHistoryGroup resultGroup = new MyHistoryGroup();
//
//        if(myHistoryGroupService.updateDeactivateGroup(parameterGroup)) {
//            resultGroup.setResult("SUCCESS");
//        } else {
//            resultGroup.setResult("FAIL");
//        }
//
//        /**
//         * Group 을 비활성화 한 다음, category 와 item 도 비활성화 한다.
//         */
//        MyHistoryCategory parameterCategory = new MyHistoryCategory();
//
//        parameterCategory.setActivateYn("Y");
//        parameterCategory.setMyHistoryMembersId(jsonGroup2.getString("myHistoryMembersId"));
//        parameterCategory.setMyHistoryGroupsIdMyHistoryGroups(jsonGroup2.getString("idMyHistoryGroups"));
//
//        List<MyHistoryCategory> parameterCategoryList = myHistoryCategoryService.selectCategoryListForGroup(parameterCategory);
//
//        for(int i=0 ; i<parameterCategoryList.size() ; i++) {
//            MyHistoryCategory myHistoryCategory = new MyHistoryCategory();
//
//            myHistoryCategory.setIdMyHistoryCategories(parameterCategoryList.get(i).getIdMyHistoryCategories());
//            myHistoryCategory.setActivateYn(jsonGroup2.getString("activateYn"));
//            myHistoryCategory.setModifyDate(jsonGroup2.getString("modifyDate"));
//            myHistoryCategory.setMyHistoryMembersId(jsonGroup2.getString("myHistoryMembersId"));
//
//            myHistoryCategoryService.updateDeactivateCategory(myHistoryCategory);
//
//            // Item 을 비활성화 한다.
//            MyHistoryItem parameterItem = new MyHistoryItem();
//
//            parameterItem.setActivateYn("Y");
//            parameterItem.setMyHistoryMembersId(jsonGroup2.getString("myHistoryMembersId"));
//            parameterItem.setMyHistoryCategoriesIdMyHistoryCategories(parameterCategoryList.get(i).getIdMyHistoryCategories());
//
//
//            List<MyHistoryItem> parameterItemList = myHistoryItemService.selectItemListForCategory(parameterItem);
//
//            for(int j=0 ; j<parameterItemList.size() ; j++) {
//                MyHistoryItem myHistoryItem = new MyHistoryItem();
//
//                myHistoryItem.setIdMyHistoryItems(parameterItemList.get(j).getIdMyHistoryItems());
//                myHistoryItem.setActivateYn(jsonGroup2.getString("activateYn"));
//                myHistoryItem.setModifyDate(jsonGroup2.getString("modifyDate"));
//                myHistoryItem.setMyHistoryMembersId(jsonGroup2.getString("myHistoryMembersId"));
//
//                myHistoryItemService.updateDeactivateItem(myHistoryItem);
//            }
//        }
//
//        return resultGroup;
//    }
}
